# api/users.py
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from db.session import get_db
from models.user import User
from schemas.user import UserOut
from controllers.console.deps import require_role, get_current_user

router = APIRouter(tags=["user"])


@router.get("/users", response_model=list[UserOut])
async def list_users(
        db: AsyncSession = Depends(get_db),
        _: User = Depends(require_role("admin"))
):
    result = await db.execute(select(User))
    return result.scalars().all()


@router.get("/user/profile", response_model=UserOut)
async def get_profile(current_user: User = Depends(get_current_user)
                      ):
    # result = await db.execute(select(User).where(User.id == user_id))
    # return result.scalar_one()
    return current_user
